<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../../common/common-head.jsp"%>
<script charset="utf-8" src="${cdnServer}kindeditor-4.1.11-zh-CN/kindeditor/kindeditor-all.js"></script>
<script charset="utf-8" src="${cdnServer}kindeditor-4.1.11-zh-CN/kindeditor/lang/zh-CN.js"></script>

<script>
    KindEditor.ready(function(K) {
        window.editor = K.create('#articleContent',{
            uploadJson : '${basePath}/article/UploadJson',
            fileManagerJson : '${basePath}/article/fileManagerJson',
            allowFileManager : true
        });
    });
</script>

<body>

<!-- begin #page-container -->


    <!-- begin #content -->
    <div id="content" class="content">

        <%@include file="../../common/common-breadcrumb-add.jsp" %>

        <!-- begin row -->
        <div class="row">
            <!-- begin col-9 -->
            <div class="col-xl-12">
                <!-- begin panel -->
                <div class="panel panel-inverse" data-sortable-id="form-stuff-1">
                    <!-- begin panel-heading -->
                    <div class="panel-heading">
                        <h4 class="panel-title" >${editObj!=null?'编辑文章':'新增文章'}</h4>
                        <div class="panel-heading-btn">
                            <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-default" data-click="panel-expand"><i class="fa fa-expand"></i></a>
                            <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-success" data-click="panel-reload"><i class="fa fa-redo"></i></a>
                            <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-warning" data-click="panel-collapse"><i class="fa fa-minus"></i></a>
                            <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-danger" data-click="panel-remove"><i class="fa fa-times"></i></a>
                        </div>
                    </div>
                    <!-- end panel-heading -->
                    <!-- begin panel-body -->
                    <div class="panel-body">
                        <form>
                            <input type="hidden" value="${editObj!=null?editObj.id:''}" id="id">
                            <div class="form-group row m-b-15">
                                <label class="col-form-label col-md-2">文章作者</label>
                                <div class="col-md-10">
                                    <input type="text" class="form-control m-b-5 col-lg-5" placeholder="文章作者" name="author" id="author" value="${editObj!=null?editObj.author:''}" />
                                    <small class="f-s-12 text-grey-darker" style="display: none">文章作者.</small>
                                </div>
                            </div>

                            <div class="form-group row m-b-15">
                                <label class="col-form-label col-md-2">文章标题</label>
                                <div class="col-md-10">
                                    <input type="text" class="form-control m-b-5 col-lg-5" placeholder="文章标题" name="title" id="title" value="${editObj!=null?editObj.title:''}" />
                                    <small class="f-s-12 text-grey-darker" style="display: none">文章标题.</small>
                                </div>
                            </div>

                            <div class="form-group row m-b-15">
                                <label class="col-form-label col-md-2">文章内容</label>
                                <div class="col-md-10">
                                    <textarea id="articleContent" name="articleContent" style="width:400px;height:300px;">
                                        ${editObj.content}
                                    </textarea>
                                    <small class="f-s-12 text-grey-darker" style="display: none">文章内容.</small>
                                </div>
                            </div>

                            <div class="form-group row">
                                <div class="col-md-7 offset-md-3">
                                    <button type="button" class="btn btn-sm btn-primary m-r-5" id="saveObj">保存</button>
                                    <button type="button" class="btn btn-sm btn-default" onclick="back()">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <!-- end panel-body -->

                </div>
                <!-- end panel -->

            </div>
            <!-- end col-6 -->
        </div>
        <!-- end row -->

    </div>
    <!-- end #content -->

<%@include file="../../common/common-script.jsp"%>

<script>
    var ctx = '${basePath}'

    function back(){
        window.location.href=ctx+"website/article/list"
    }

    $(function(){

        $("#saveObj").click(function(){
            var id = $("#id").val()
            var author = $("#author").val()
            var title = $("#title").val()
            var content = editor.html()

            $.ajax({
                type:'post',
                url:ctx+'website/article/add',
                data:JSON.stringify({"id":id,"author":author,"title":title,"content":content}),
                success:function(res){
                    if(res == "1000"){
                        window.location.href=ctx+"website/article/list"
                    }
                }
            })

        })
    })



</script>

</body>
</html>
